#include "parameterint.h"
#include "parameterdouble.h"

#include "parameters.h"

Parameters::~Parameters()
{
    for (int i = 0; i < m_vecParas.size(); ++i) {
        delete m_vecParas[i];
    }
}

bool Parameters::addPara(const char *name, double val)
{
    ParameterDouble *para = new ParameterDouble();
    para->setValue(val);
    m_vecParas.push_back(para);
    return true;
}

bool Parameters::addPara(const char *name, int val)
{
    ParameterInt *para = new ParameterInt();
    para->setName(name);
    para->setValue(val);
    m_vecParas.push_back(para);
    return true;
}

bool Parameters::getPara(const char *name, double &val)
{
    for (int i = 0; i < m_vecParas.size(); ++i) {
        if (m_vecParas[i]->getName() == name) {
            ParameterDouble *para;
            if (para = dynamic_cast<ParameterDouble*>(m_vecParas[i])) {
                val = para->getValue();
                return true;
            }
        }
    }
    return false;
}

bool Parameters::getPara(const char *name, int &val)
{
    for (int i = 0; i < m_vecParas.size(); ++i) {
        if (m_vecParas[i]->getName() == name) {
            ParameterInt *para;
            if (para = dynamic_cast<ParameterInt*>(m_vecParas[i])) {
                val = para->getValue();
                return true;
            }
        }
    }
    return false;
}